package com.akl.ssmspringboot.controller;

import com.akl.ssmspringboot.entity.User;
import com.akl.ssmspringboot.service.UserService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @ClassName:
 * @Author: Guoxy
 * @Date: Created in 15:14 2018/11/28
 * @Version:1.0
 */
@Controller
@RequestMapping("/dataTables")
public class TableController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;


    @RequestMapping("/table")
    public String table() {
        ModelAndView mv = new ModelAndView("dataTables/table");
        return "./dataTables/table";
    }

    /**
     * json后缀名ajax请求
     * @return
     */
    @RequestMapping("/ajax/arrays.json")
    @ResponseBody
    public JSONObject arrays() {
        List<User> result = userService.findAll();
        JSONObject obj = new JSONObject();
        obj.put("code", 0);
        obj.put("msg", "success");
        obj.put("data", result);
        return obj;
    }

}
